package com.proxy.pattern.handler;

import com.proxy.pattern.service.UserService;
import lombok.extern.slf4j.Slf4j;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

/**
 * @author cc
 * @classname UserHandler
 * @description 定义代理类的增强逻辑
 * @date 2022/3/27 14:08
 */
@Slf4j
public class UserInvocationHandler implements InvocationHandler {

    private UserService userService;

    public UserInvocationHandler(UserService userService) {
        this.userService = userService;
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        log.info("增强逻辑");
        Object obj = method.invoke(userService, args);
        log.info("增强逻辑");
        return obj;
    }

}
